<?php

// intialize pmvc
include "../pmvc/lib/pmvc.php";
pmvc_initialize();

// balls
use pmvc\ioc\XmlObjectFactory;

// define some classes for testing
class ObjectA {
	public $objectName;
	public $whatever;
}

// define some classes for testing
class ObjectB {
	public function ObjectB($prop1, $prop2) {
		$this->prop1 = $prop1;
		$this->prop2 = $prop2;
	}
	public $prop1;
	public $prop2;
}

// create the factory
$factory = new XmlObjectFactory(Array("testContext1.xml"));
$factory2 = new XmlObjectFactory(Array("testContext2.xml"), $factory);

$object1 = $factory->getObjectById("object1");
assert(isset($object1));
assert($object1==$factory->getObjectByName("object1"));

$object2 = $factory->getObjectById("object2");
assert(isset($object2));
assert($object1==$object2->whatever);

$object3 = $factory->getObjectById("object3");
assert(isset($object3));
assert($object3==$factory->getObjectByName("object3"));
assert($object1==$object3->prop1);
assert($object2==$object3->prop2);

$object4 = $factory->getObjectById("object4");
assert(isset($object4));
assert($object4->prop1=="one");
assert($object4->prop2=="two");

$object5 = $factory2->getObjectById("object5");
assert(isset($object5));
assert($object5->prop1=="one");
assert($object5->prop2=="two");

try {
	$factory->getObjectById("object5");
	assert(false);
} catch(Exception $e) {
	assert(true);
}

$_object1 = $factory2->getObjectById("object1");
assert(isset($_object1));
assert($object1==$_object1);

assert(count($factory->getObjectIds())==4);
assert(count($factory2->getObjectIds())==1);

assert(count($factory->getObjectNames())==2);
assert(count($factory2->getObjectNames())==0);

assert(count($factory->getObjectsOfType("ObjectA"))==2);
assert(count($factory->getObjectsOfType("ObjectB"))==2);
assert(count($factory2->getObjectsOfType("ObjectA"))==2);
assert(count($factory2->getObjectsOfType("ObjectB"))==3);

assert(count($factory->getObjectIdsOfType("ObjectA"))==2);
assert(count($factory->getObjectIdsOfType("ObjectB"))==2);
assert(count($factory2->getObjectIdsOfType("ObjectA"))==0);
assert(count($factory2->getObjectIdsOfType("ObjectB"))==1);

assert(count($factory->getObjectNamesOfType("ObjectA"))==1);
assert(count($factory->getObjectNamesOfType("ObjectB"))==1);
assert(count($factory2->getObjectNamesOfType("ObjectA"))==0);
assert(count($factory2->getObjectNamesOfType("ObjectB"))==0);


?>